package com.niit.onlinemusicserver34.common;

import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;

/**
 * Token 检查是否携带token的拦截器
 */
public class TokenInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
//
//        String[] whiteList={"/banner/getAllBanner","/singer/list","/song","/user/login/status"};
//
//        if(Arrays.stream(whiteList).toList().contains(request.getRequestURI())){
//            return HandlerInterceptor.super.preHandle(request, response, handler);
//        }

//        String token = request.getHeader("token");
//        if(null==token){
//            throw new RuntimeException("访问未授权，请先登录！");
//        }
//        if(!JwtUtils.verify(token)){
//            throw new RuntimeException("非法的Token");
//        }
        return HandlerInterceptor.super.preHandle(request, response, handler);
    }
}
